import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
// import Login from '../views/user/login.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    redirect: '/deviceManage',
    component: Home
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/user/login.vue')
  },
  {
    path: '/deviceManage',
    name: 'DeviceManage',
    component: () => import('../views/deviceManage/index.vue')
  },
  {
    path: '/lock',
    name: 'Lock',
    component: () => import('../views/lock/index.vue')
  },
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  var token = window.localStorage.getItem('token')
  if (!token && to.path !== '/login') return next('login')
  next()
})

export default router
